// 函数作为参数
function forEach(array, fn) {
  for (let i = 0; i < array.length; i++) {
    fn(array[i]);
  }
}

let arr = [1, 2, 3, 4];
// forEach(arr, (item) => {
//   console.log(item);
// })

function filter(array, fn) {
  let results = [];
  for (let i = 0; i < array.length; i++) if (fn(array[i])) results.push(array[i]);
  return results;
}

let a = filter(arr, (item) => {
  return item % 2 === 0;
})

console.log(a);